//
//  newNoteViewController3.m
//  Assignment3
//
//  Created by volsen on 3/11/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "newNoteViewController3.h"
#import "Assignment3AppDelegate.h"


@implementation newNoteViewController3

// Synthesize directives were added by Vince on 3/26

@synthesize theCatagory;
@synthesize theTitle;
@synthesize theNote;

// Method to hide keyboard after DONE key is selected added by Vince on 3/26

-(IBAction) hideKeyboard:(id)sender{
	[theCatagory resignFirstResponder];
	[theTitle resignFirstResponder];
}


// The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization.
    }
    return self;
}
*/

/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations.
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}

// Method for save button added by Vince on 3/26

-(IBAction)saveNote{
	
	NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
	
	[dictionary setValue:[theTitle text] forKey:@"title"];
	[dictionary setValue:[theCatagory text] forKey:@"category"];
	[dictionary setValue:[theNote text] forKey:@"note"];
	[dictionary setValue:[NSDate date] forKey:@"date"];
	
	// [NSUserDefaults standardUserDefaults] is essentially a dictionary
	// we call [... objectForKey:@"notes"] on it, which returns the NSMutableArray we made in AppDelegate
	// then we call [... addObject:dictionary] on that array, which adds the newly created note to that array
	
//	[[[NSUserDefaults standardUserDefaults] objectForKey:@"notes"] addObject:dictionary];
	[[(Assignment3AppDelegate *)[[UIApplication sharedApplication] delegate] allNotes] addObject:dictionary];
	
	// THIS IS HOW YOU GET TO ALL OF THE NOTES IN THE APP ----> [(Assignment3AppDelegate *)[[UIApplication sharedApplication] delegate] allNotes]
	
	[dictionary release];
	
	[[self navigationController] popViewControllerAnimated:YES];
}

@end
